package com.ruoyi.web.controller.ring;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.UserFoodInfo;
import com.ruoyi.ring.service.IRingHealthPlanService;
import com.ruoyi.ring.service.IUserFoodInfoService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 饮食记录
 * 
 * @author liuwp
 * @date 2025-09-04
 */
@RestController
@RequestMapping("/ring/user_food_info")
public class UserFoodInfoController extends BaseController
{
    @Resource
    private IUserFoodInfoService userFoodInfoService;

    @Resource
    private ISysConfigService configService;
    @Resource
    private IRingHealthPlanService ringHealthPlanService;
    /**
     * 查询饮食记录列表
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFoodInfo userFoodInfo)
    {
        startPage();
        List<UserFoodInfo> list = userFoodInfoService.selectUserFoodInfoList(userFoodInfo);
        return getDataTable(list);
    }

    /**
     * 导出饮食记录列表
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:export')")
    @Log(title = "饮食记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserFoodInfo userFoodInfo)
    {
        List<UserFoodInfo> list = userFoodInfoService.selectUserFoodInfoList(userFoodInfo);
        ExcelUtil<UserFoodInfo> util = new ExcelUtil<UserFoodInfo>(UserFoodInfo.class);
        util.exportExcel(response, list, "饮食记录数据");
    }

    /**
     * 获取饮食记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userFoodInfoService.selectUserFoodInfoById(id));
    }

    /**
     * 新增饮食记录
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:add')")
    @Log(title = "饮食记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFoodInfo userFoodInfo)
    {
        return toAjax(userFoodInfoService.insertUserFoodInfo(userFoodInfo));
    }

    /**
     * 修改饮食记录
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:edit')")
    @Log(title = "饮食记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFoodInfo userFoodInfo)
    {
        return toAjax(userFoodInfoService.updateUserFoodInfo(userFoodInfo));
    }

    /**
     * 删除饮食记录
     */
    @PreAuthorize("@ss.hasPermi('ring:user_food_info:remove')")
    @Log(title = "饮食记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userFoodInfoService.deleteUserFoodInfoByIds(ids));
    }


}
